<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%-- <%@include file="../../common/taglib/taglib.jsp"%> --%>
<script type="text/javascript">
	function selectDate(str, obj) {
		var now = new Date(); //获取当前时间
		var year = now.getFullYear(); //获取当前日期的年份部分
		var month = now.getMonth() + 1 + ""; //获取当前日期的月份部分
		var day = now.getDate() + ""; //获取当前日期的天数部分
		if (day.length == 1) {
			day = "0" + day;
		}
		//获取当前月份包含的天数
		var nowdays = new Date(year, month, 0).getDate();
		var lastMonth = month - 1 + "";
		var lastMonthdays = new Date(year, lastMonth, 0).getDate() + "";
		if (month.length == 1) {
			month = "0" + month;
		}
		if (lastMonth.length == 1) {
			lastMonth = "0" + lastMonth;
		}
		if (lastMonthdays.length == 1) {
			lastMonthdays = "0" + lastMonthdays;
		}
		var startTime = "";
		var endTime = "";
		switch (str) {
		case "toDay":
			startTime = year + "-" + month + "-" + day;
			endTime = year + "-" + month + "-" + day;
			break;
		case "lastMonth":
			if (lastMonth == 0) {
				lastMonth = 12;
				year = year - 1;
			}
			startTime = year + "-" + lastMonth + "-01";
			endTime = year + "-" + lastMonth + "-" + lastMonthdays;
			break;
		case "currentMonth":
			startTime = year + "-" + month + "-01";
			//endTime = year + "-" + month + "-" + day;
			endTime = year + "-" + month + "-" + nowdays;
			break;
		case "lastYear":
			startTime = (year - 1) + "-01-01";
			endTime = (year - 1) + "-12-31";
			break;
		case "currentYear":
			startTime = year + "-01-01";
			endTime = year + "-12-31";
			break;
		}
		$("#beginDateMerchant").val(startTime);
		$("#endDateMerchant").val(endTime);

	}

	// 清空表单
	function clearFormList() {
		$(':input', "form[action='${baseURL }/agent/merchantList']").not(
				':button, :submit, :reset, :hidden').val('').removeAttr(
				'checked').removeAttr('selected');
	}
</script>
<div class="pageHeader">
	<form id="pagerForm" onsubmit="return navTabSearch(this);" action="${baseURL }/agent/merchantList" method="post">
		<!-- 分页表单参数 -->
		<%@include file="../common/pageParameter.jsp"%>
		<div class="searchBar">
			<table class="searchContent">
				<tr>
					<td>
						<label>一级代理商编号：</label>
						<input type="text" name="agent.userNo" size="25" maxlength="128" class="readonly" value="${agentNo}" />
						<a style="float: right;" class="btnLook" href="${baseURL}/user/info/lookupList?userType=AGENT" lookupGroup="agent">选择代理商</a>
					</td>
					<td>
						<label>状态：</label>
						<select name="status" id="status">
							<option value="">全部</option>
							<c:forEach items="${merchantStatusEnumsList }" var="model">
								<option value="${model.name }" <c:if test="${model.name eq param.status }">selected="selected"
							</c:if>>${model.desc }</option>
							</c:forEach>
						</select>
					</td>
					<td>
						<label>创建时间：</label>
						<input type="text" name="beginDateMerchant" value="${param.beginDateMerchant}" id="beginDateMerchant" class="date" size="10" readonly="readonly" />
						-
						<input type="text" name="endDateMerchant" value="${param.endDateMerchant}" id="endDateMerchant" class="date" size="10" readonly="readonly" />
						<a href="#" id="a_Date_2" style="color: blue;" onclick="selectDate('toDay',this)">今天</a> &nbsp; <a href="#" id="clear" style="color: blue;" onclick="clearFormList()">清空条件</a>
					</td>
					<td>
						<div class="subBar">
							<ul>
								<li>
									<div class="buttonActive">
										<div class="buttonContent">
											<button type="submit">查询</button>
										</div>
									</div>
								</li>
							</ul>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</form>
</div>
<div class="pageContent">

	<!-- 修改部分  -->
	<div class="panelBar">
		<ul class="toolBar">
		    <c:if test="${agentNo != null }">
		    <z:permission name="agentMerchant:manager:add">
			<li>
			    <a title="商户添加" class="add" href="${baseURL }/agentMerchant/addUI/?agentNo=${agentNo}" 
			    target="navTab" mask="true" width="560" height="400"><span>添加</span></a>
			</li>
			<li class="line">line</li>
			</z:permission>
			</c:if>
		</ul>
	</div>
	<!-- 修改部分  -->

	<table class="table" targetType="navTab" asc="asc" desc="desc" width="100%" nowrapTD="false" layoutH="140">
		<thead>
			<tr>
				<th width="30">序号</th>
				<th>创建时间</th>
				<th>商户编号</th>
				<th>商户简称</th>
				<th>层级关系</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="item" items="${pageBean.recordList}" varStatus="st">
				<tr target="sid_user" rel="${item.id}">
					<td>${st.index+1 }</td>
					<td>
						<fmt:formatDate value="${item.createTime }" pattern="yyyy-MM-dd HH:mm:ss" />
					</td>
					<td>${item.merchantNo }</td>
					<td>${item.merchantName }</td>
					<td>
						<c:if test="${not empty item.firstAgentNo }">
								${item.firstAgentName }-[${item.firstAgentNo }]
							</c:if>
						<c:if test="${not empty item.secondAgentNo }">
							<br />&nbsp;&nbsp;∟${item.secondAgentName }-[${item.secondAgentNo }]
							</c:if>
						<c:if test="${not empty item.thirdAgentNo }">
							<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;∟
							 	${item.thirdAgentName }-[${item.thirdAgentNo }]
							 </c:if>
					</td>
					<td>
						<c:forEach items="${merchantStatusEnumsList }" var="mStatus">
							<c:if test="${mStatus.name eq item.status }">
								<font color="red">${mStatus.desc}</font>
							</c:if>
						</c:forEach>
					</td>
					<td>
					
					<z:permission value="agentMerchant:manager:list">
						<a title="商户查看" href="${baseURL }/agentMerchant/view?id=${item.id }" target="navTab" style="color: blue;">[查看]</a>&nbsp; 
					</z:permission>
					
					<z:permission name="agent:rate:edit">
					<c:if test="${item.status == 'ACTIVE'}">
						<a title="商户编辑" target="navTab" href="${baseURL }/agentMerchant/editUI?id=${item.id}" style="color: blue;">[编辑]</a>
					</c:if>
					</z:permission>
					
					<z:permission name="agent:rate:edit">
					<c:if test="${item.status == 'ACTIVE'}">
						<a title="设置费率" target="dialog" href="${baseURL }/agentMerchant/setRateUI?merchantNo=${item.merchantNo}" rel="addMerchantInfo" style="color: blue;" width="830" height="550">[设置费率]</a>
					</c:if>
					</z:permission>
					
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<!-- 分页条 -->
	<%@include file="../common/pageBar.jsp"%>
</div>